<%--
  Created by IntelliJ IDEA.
  User: cjrh2
  Date: 2025/9/20
  Time: 11:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
</head>
<body>

<%--<form action="/mvc/method1" method="post">
    <input type="text" name="username"> <br>
    <input type="password" name="password"> <br>

    <input type="submit" value="提交">
</form>--%>


<%--<button id="btn">异步提交</button>--%>


<%--<a href="/mvc/queryAllOrder" onclick="showOrders(this.href);return false">查询所有订单</a>--%>


<%--<div id="orders"></div>--%>


<%--<form action="/mvc/login" method="post" onsubmit="return check();">

    <input type="text" name="username" id="name" onblur="checkNameLength();">
    <span id="msg1"></span>
    <br>
    <input type="password" name="password" id="pswd" onblur="checkPswdLength()"> <br>
    <span id="msg2"></span>
    <input type="submit" value="提交">
</form>--%>


<form action="/mvc/handle01" method="post">
    姓名:<input type="text" name="username">${errors.username}<br>
    密码:<input type="text" name="password">${errors.password}<br>
    邮箱:<input type="text" name="email">${errors.email}<br>
    手机号:<input type="text" name="phone">${errors.phone}<br>
    <%--    生日:<input type="text" name="birth">${errors.birth}<br>--%>
    年龄:<input type="number" name="age">${errors.age}<br>
    <input type="submit" value="提交">
</form>


<script>

    function check() {

        if (checkNameLength() && checkPswdLength()) {
            return true;
        } else {
            return false;
        }
    }

    function checkNameLength() {

        var val = $("#name").val();
        var flag1;
        if (val.length < 5) {
            $("#msg1").html('用户名长度至少5位!');
            flag1 = true;
        } else {
            $("#msg1").html('');
            flag1 = false;
        }
        return flag1;
    }

    function checkPswdLength() {
        var val = $("#pswd").val();
        var flag2;
        if (val.length < 6) {
            $("#msg2").html('密码长度至少6位!');
            flag2 = true;
        } else {
            $("#msg2").html('');
            flag2 = false;
        }
        return flag2;
    }

    function showOrders(href) {
        $.ajax({
            dataType: "json",
            success: function (data) { /* 成功回调 */
                $.each(data, function (index, e) {
                    console.log(index + "," + e);
                    // console.log(e.id);
                    // console.log(e.name);
                    let html = $('<h3>').html(e.id + "," + e.name + "," + e.ordertime);
                    $("#orders").append(html);
                })

            }, // GET/POST/PUT/DELETE 等
            type: "get", // json/xml/html/text/script/jsonp
            url: href
        });
    }

    // obj.test();
    // parseFloat();

    /*    $("#btn").click(function () {
            let msg = {'username': "root", 'password': 123456};
            let str = JSON.stringify(msg);
            $.ajax({
                url: "/mvc/testb",
                type: "post", // GET/POST/PUT/DELETE 等
                data: str, // 发送到服务器的数据
                contentType: "application/json",
                success: function (response) { /!* 成功回调 *!/
                }
            });
        })*/

</script>

</body>
</html>
